package jzbank.controller;

import io.swagger.annotations.*;
import jzbank.common.responsTool.Res;
import jzbank.pojo.dto.DataExportDTO;
import jzbank.pojo.from.DataExportTask;
import jzbank.service.DataExportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/export")
@Api(tags = "数据导出任务管理") // 指定模块名称
public class DataExportController {

    @Autowired
    private DataExportService service;

    /**
     * 添加任务信息
     * @param dataExportTask 任务信息
     * @return 成功/失败
     */
    @ApiOperation("添加任务信息")
    @PostMapping(value = "/create", consumes = "application/json", produces = "application/json")
    public Res create(@RequestBody DataExportTask dataExportTask) {
        System.out.println("添加任务：" + dataExportTask.toString());
        service.createDataExportTask(dataExportTask);
        return Res.ok();
    }

    /**
     * 查询所有任务列表
     * @return 任务列表
     */
    @ApiOperation("查询所有任务列表")
    @GetMapping("/list")
    public Res list() {
        System.out.println("查询任务列表");
        List<DataExportDTO> list = service.selectAllDataExportTask();
        return Res.ok(list);
    }

    /**
     * 删除任务
     * @param id 任务ID
     * @return
     */
    @ApiOperation("删除任务")
    @ApiImplicitParam(name = "id", value = "任务ID", required = true, dataType = "String")
    @PostMapping("/remove")
    public Res remove(@RequestParam String id) {
        System.out.println("删除任务：" + id);
        service.deleteDataExportTaskById(id);
        return Res.ok();
    }

    /**
     * 根据ID查询任务
     * @param id 任务ID
     * @return 任务信息
     */
    @ApiOperation("根据ID查询任务")
    @ApiImplicitParam(name = "id", value = "任务ID", required = true, dataType = "String")
    @PostMapping("/get")
    public Res selectByid(@RequestParam String id) {
        System.out.println("查询任务列表");
        DataExportDTO dataExportDTO = service.selectDataExportTaskById(id);
        return Res.ok(dataExportDTO);
    }

    /**
     * 添加任务信息
     * @param dataExportDTO 任务信息
     * @return 成功/失败
     */
    @ApiOperation("修改任务信息")
    @PostMapping(value = "/update", consumes = "application/json", produces = "application/json")
    public Res update(@RequestBody DataExportDTO dataExportDTO) {
        System.out.println("修改任务：" + dataExportDTO.toString());
        service.updateDataExportTask(dataExportDTO);
        return Res.ok();
    }
}